package com.ai.chatbackend.controller.ai;

import com.ai.chatbackend.pojo.vo.AiChatHistoryVO;
import com.ai.chatbackend.service.ai.ChatService;
import com.easyUtils.utils.resultUtil.Result;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.util.List;

@RestController
@RequestMapping("/ai-chat")
public class ChatController {

    @Autowired
    private ChatClient chatClient;

    @Autowired
    private ChatService chatService;

    @GetMapping("/prompt")
    public Flux<String> chat(String prompt,String chatId){
        return chatClient.prompt()
                .user(prompt)
                .advisors(advisorSpec -> advisorSpec.param(ChatMemory.CONVERSATION_ID,chatId))
                .stream().content();
    }
    @GetMapping("/history")
    public Result<List<AiChatHistoryVO>> getHistory(String chatId){
        List<AiChatHistoryVO> list=chatService.getHistory(chatId);
        return Result.success(list);
    }


}

